import math

class DataAnalysiser:
    def __init__(self):
        pass

    def takeSecond(self, element):
        return element[1]

    def Odd(self, number):
        if (number % 2) == 0:
            # Even
            return False
        else:
            return True

    def Average(self, sourceList):
        results = 0
        for source in sourceList:
            result = source[0] * source[1]
            results+=result
        results = results / len(sourceList)
        return results

    def Median(self, sourceList):
        sourceList.sort()
        result = 0
        if self.Odd(len(sourceList)) == True:
            result = sourceList[len(sourceList)+1 // 2 - 1]
        else:
            list = [[len(sourceList) // 2, 1], [(len(sourceList) // 2) + 1, 1]]
            result = self.Average(list)

        return result

    def ArithmeticMode(self, sourceList):
        sourceList.sort()
        occurrences = [
           (0, 0)
        ]
        for element in sourceList:
            occurrence = (element, sourceList.count(element))
            occurrences.append(occurrence)
        occurrences.sort(key=self.takeSecond, reverse=True)
        return occurrences[0][0]

    def ArithmeticRange(self, sourceList):
        sourceList.sort()
        arange = max(sourceList) - min(sourceList)
        return arange

    def ArithmeticVariance(self, sourceList):
        sourceList.sort()
        weightedList = []
        for element in sourceList:
            weightedList.append((element, 1))
        average = self.Average(weightedList)
        total = 0
        for number in sourceList:
            total+=(number - average)**2
        variance = total / len(sourceList)
        return variance

    def StandardDeviation(self, sourceList):
        variance = self.ArithmeticVariance(sourceList)
        return math.sqrt(variance)
        

if __name__ == '__main__':
    testSet = [75,74,74,76,73,76,75,77,77,74,74,75,75,76,73,76,73,78,77,72]
    inst = DataAnalysiser()
    print(inst.ArithmeticVariance(testSet))
